﻿// JavaScript Document
//init the store content
var house = new Ext.data.SimpleStore({
   fields: [
			{name:'id',type:"string"},
      		{name:'housename',type:"string"},
			{name:"housepos",type:"string"},
			{name:"termnum",type:"float"},
			{name:"options",type:"string"}
     ]
    });


//init the gird	
var grid=null;   
function houseInit()
{
	HouseManager.getHouseList(showDate);
	//每30秒更新一次
	window.setInterval(houseReload,30000);
}
function houseReload()
{
	HouseManager.getHouseList(reloadDate); 
}
function reloadDate(data)
{
	house.loadData(data);
	try
	{
		grid.store.reload();
	}
	catch(e)
	{
		
	}
}
function showDate(data)
{
	Ext.onReady(function(){

	    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	
	    var myData =data;
	
	
	    // create the data store
	    
	    house.loadData(myData);
	
	    // create the Grid
	    grid = new Ext.grid.GridPanel({
		        store: house,
		        columns: [
		            {header: "大棚名称", width:140, sortable: true, dataIndex: 'housename'},
		            {header:"大鹏位置",width:240,sortable:true,dataIndex:'housepos'},
					{header:"终端数量",width:100,sortable:true,dataIndex:'termnum'},
					{header:"操作选项",width:120,sortable:false,dataIndex:'options'}
		        ],
		        stripeRows: true,
		        height:220,
		        width:624
		    });
		
		    grid.render('house');
	
	});
}
//function deleteHouse
function deleteHouse(id,name)
{
	if (confirm("您确定要删除大棚["+name+"]吗？")==true)
	{
		HouseManager.del(id,reloadDate);
	}
}
//function detailhoust
function houseDetail(id,name)
{
	document.all["ListTitle"].innerHTML="大棚["+name+"]终端列表";
	document.all["ListOptions"].innerHTML="<a href='javascript:reToHouse()' class='action'><img src='image/return.gif' />返回大棚列表</a>&nbsp;&nbsp;<a href='javascript:addTerminal()' class='action'><img src='image/newTerminal.gif' />新增终端</a>";
	document.all["house"].style.visibility="hidden";
	document.all["terminal"].style.visibility="visible";
	document.all["house"].style.height=0;
	terminalInit(id);
}
